Published 2010-02-17 11:10:00
   // some globally accessable constant.
    Builder.atoms = {
       "STRING" : Gdk.atom_intern("STRING")
    }SOURCE: 
  
  
    Gtk.drag_source_set (
        this.el,            /* widget will be drag-able */
        Gdk.ModifierType.BUTTON1_MASK,       /* modifier that will start a drag */
        null,            /* lists of target to support */
        0,              /* size of list */
        Gdk.DragAction.COPY         /* what to do with data after dropped */
     );
     targets = new Gtk.TargetList();
     targets.add( Builder.atoms["STRING"], 0, 0);
     Gtk.drag_source_set_target_list(this.el, targets);
     Gtk.drag_source_add_text_targets(this.el); 
TARGET:
      
        Gtk.drag_dest_set
        (
                this.el,              /* widget that will accept a drop */
                Gtk.DestDefaults.MOTION  | Gtk.DestDefaults.HIGHLIGHT,
                null,            /* lists of target to support */
                0,              /* size of list */
                Gdk.DragAction.COPY         /* what to do with data after dropped */
        );
        targets = new Gtk.TargetList();
        targets.add( Builder.atoms["STRING"], 0, 0);
        Gtk.drag_dest_set_target_list(this.el, targets);
        Gtk.drag_dest_add_text_targets(this.el);
SOURCE: 
 'drag-begin' : function (w, ctx, ud) 
                                    {
            // we could fill this in now...
            Seed.print('SOURCE: drag-begin');
             
            // find what is selected in our tree...
            var iter = new Gtk.TreeIter();
            var s = this.selection;
            s.get_selected(_model, iter);
            // set some properties of the tree for use by the dropped element.
            var value = new GObject.Value('');
            _model.el.get_value(iter, 0, value);
            this.el.dragData = value.value;
            this.el.dropList = _model.provider.getDropList(value.value);
            // make the drag icon a picture of the node that was selected
            var path = _model.el.get_path(iter);
            var pix = this.el.create_row_drag_icon ( path);
            Gtk.drag_set_icon_pixmap (ctx,
                pix.get_colormap(),
                pix,
                null,
                -10,
                -10);
            
            return true;
        },
       'drag-end' : function () 
        {
            Seed.print('SOURCE: drag-end');
            this.el.dragData = false;
            this.el.dropList = false;
            return true;
        },SOURCE
 
        'drag-data-get' : function (w, ctx, selection_data, target_type,  time, ud) 
        {
            
            Seed.print('Palete: drag-data-get: ' + target_type);
            selection_data.set_text(this.dragData ,this.dragData.length);
            
            return true;
        },TARGET:
    'drag-motion' : function (w, ctx,  x,   y,   time, ud) 
    {
        
 
        var src = Gtk.drag_get_source_widget(ctx);
        // a drag from  elsewhere...- prevent drop..
        if (!src.dragData) {
            Gdk.drag_status(ctx, 0, time);
            return true;
        }
        
        Gdk.drag_status(ctx, Gdk.DragAction.COPY,time);
         
        return true;
    },
'drag-drop'  : function (w, ctx, x, y,time, ud) 
    {
                
        Seed.print("TARGET: drag-drop");
       
        Gtk.drag_get_data
        (
                w,         /* will receive 'drag-data-received' signal */
                ctx,        /* represents the current state of the DnD */
                Builder.atoms["STRING"],    /* the target type we want */
                time            /* time stamp */
        );
        
        var source = Gtk.drag_get_source_widget(ctx);
        Seed.print("Browser: source.DRAGDATA? " + source.dragData);
                
        /* No target offered by source => error */
       
        return  true;
        
    }
   'drag-data-received' : function (w, ctx,  x,  y, sel_data,  target_type,  time, ud) 
        {
            Seed.print("Browser: drag-data-received");
            delete_selection_data = false;
            dnd_success = false;
            /* Deal with what we are given from source */
            if( sel_data && sel_data.length ) {
                
                if (ctx.action == Gdk.DragAction.ASK)  {
                    /* Ask the user to move or copy, then set the ctx action. */
                }
                if (ctx.action == Gdk.DragAction.MOVE) {
                    delete_selection_data = true;
                }
                var source = Gtk.drag_get_source_widget(ctx);
                // we can send stuff to souce here...
                dnd_success = true;
            }
            if (dnd_success == false)
            {
                    Seed.print ("DnD data transfer failed!\n");
            }
            Gtk.drag_finish (ctx, dnd_success, delete_selection_data, time);
            return true;
        },